import java.awt.*;
import java.awt.event.*;

import javax.swing.*;

import java.io.*;
import java.applet.AppletContext.*;
import java.sql.SQLException;
import java.util.*;

import javax.swing.event.*;

import java.lang.reflect.*;

import javax.swing.border.*;
import javax.swing.plaf.basic.*;

import  java.awt.image.ImageConsumer ;
import java.awt.image.ImageObserver; 
import   java.applet.AudioClip;

import javax.swing.filechooser.FileView;

import java.net.*;


public class Addcust extends JFrame
{
	JTextField t1,t2,t3,t4;
	JTextArea a2,a3,a5,a4,a6,a7;
	JButton b1,b2,b3,b4,b5,b6,b7,b8,b9,b10;
	JLabel userNamelbl,l2,l3,l4,l8,l9,l10,l11,l12,l13,l14; 
	JPanel jp1,jp2,jp3,jp4,jp5,jp6;
	FileReader rd1;
	JTextField read1;
	FileWriter wr1;
	String year="20";
	Container cp;
	
	private sqlAPI look = new sqlAPI();

	Addcust()
	{
		super("Add customer");
		setVisible(true);
		getContentPane().setBackground(new Color(95, 158, 160));
		
		setSize(350,450);
        setLocation(150,130);
		cp=getContentPane();
		cp.setLayout(null);

		jp1=new JPanel(null,true);
		jp1.setBackground(new Color(0, 128, 128));

		userNamelbl=new JLabel("User Name");
		userNamelbl.setForeground(new Color(143, 188, 143));
		userNamelbl.setBounds(10,10,150,25);
		jp1.add(userNamelbl);

		t1=new JTextField();
		t1.setBounds(100,10,120,25);
		jp1.add(t1);

		l2=new JLabel("Password");
		l2.setBounds(10,40,150,25);
		jp1.add(l2);

		Date d=new Date();
		int date=d.getDate();
		int mon=d.getMonth();
		mon=mon+1;
		int y=d.getYear();

		String str=y+"";
		int len=str.length();

		for(int i=0;i<len;i++)
		{

			if(i>0)
			{
				year=year+str.charAt(i);
			}
		}
		String issue=date+"/"+mon+"/"+year;

		t2=new JTextField();
		t2.setBounds(100,40,120,25);
		jp1.add(t2);


		l3=new JLabel("Full Name");
		l3.setForeground(new Color(143, 188, 143));
		l3.setBounds(10,70,150,25);
		jp1.add(l3);

		t3=new JTextField("");
		t3.setBounds(100,70,120,25);
		jp1.add(t3);

		b1=new JButton("Register");
		b1.setBounds(10,310,90,20);
		jp1.add(b1);

		b2=new JButton("Reset");
		b2.setBounds(120,310,90,20);
		jp1.add(b2);

		b3=new JButton("Cancel");
		b3.setBounds(230,310,90,20);
		jp1.add(b3);

		jp1.setBounds(10,10,350,350);
		cp.add(jp1);

		b2.addActionListener(new ActionListener()
		{
			public void actionPerformed(ActionEvent e)
			{
				t1.setText("");
				
				t4.setText("");
				t2.setText("");
				
			}
		});


		b3.addActionListener(new ActionListener()
		{
			public void actionPerformed(ActionEvent e)
			{
				setVisible(false);
			}
		});


		b1.addActionListener(new ActionListener()
		{
			public void actionPerformed(ActionEvent e)
			{
				try{
					String uname = t1.getText();
					System.out.println(uname);
					String pword = t2.getText();
					System.out.println(pword);
					String name = t3.getText();
					System.out.println(name);
					String inString ="";
//					if(uname.length() > 254) {
//						inString += "Author Name ";
//					}
//					if(pword.length() > 254) {
//						inString += "Password";
//					}
//					if(name.length() > 254) {
//						inString += "Name";
//					}
//					if(inString != "") {
//						JOptionPane.showConfirmDialog(jp1, inString + "is greater than 254 characters, please shorten");
//					}
					int addUser = look.addUser(uname, pword, name, false);
					System.out.println("ADDUSER RETURND: " + addUser);
					setVisible(false);

				}catch(Exception ge){
					System.out.println(ge);
					ge.printStackTrace();
				}
			}
		});
	}
}